<template>
	<view class="container">
		<!-- 顶部搜索栏 -->
		<view class="card flex justify-between mb-20 search-bar">
			<view class="flex align-center search-input-container">
				<text class="iconfont icon-search search-icon"></text>
				<input type="text" placeholder="搜索景点、酒店、攻略" class="search-input" />
			</view>
			<view class="search-button">搜索</view>
		</view>
		
		<!-- 轮播图 -->
		<swiper class="card mb-20" indicator-dots autoplay interval="5000" duration="1000" style="height: 300rpx;" indicator-color="rgba(255,255,255,0.5)" indicator-active-color="#4caf50">
			<swiper-item>
				<image src="/static/banner1.jpg" mode="aspectFill" style="width: 100%; height: 300rpx;"></image>
			</swiper-item>
			<swiper-item>
				<image src="/static/banner2.jpg" mode="aspectFill" style="width: 100%; height: 300rpx;"></image>
			</swiper-item>
			<swiper-item>
				<image src="/static/banner3.jpg" mode="aspectFill" style="width: 100%; height: 300rpx;"></image>
			</swiper-item>
		</swiper>
		
		<!-- 功能入口 -->
		<view class="card mb-20">
			<view class="grid grid-col-5 text-center">
				<view class="grid-item p-20" @click="goToPage('/pages/ticket/index')">
					<text class="iconfont icon-ticket animated-icon" style="font-size: 50rpx; color: #4caf50;"></text>
					<text class="block mt-10">购票</text>
				</view>
				<view class="grid-item p-20" @click="goToPage('/pages/hotel/index')">
					<text class="iconfont icon-hotel animated-icon" style="font-size: 50rpx; color: #8bc34a;"></text>
					<text class="block mt-10">订房</text>
				</view>
				<view class="grid-item p-20" @click="goToPage('/pages/info/index')">
					<text class="iconfont icon-info animated-icon" style="font-size: 50rpx; color: #cddc39;"></text>
					<text class="block mt-10">资讯</text>
				</view>
				<view class="grid-item p-20" @click="goToPage('/pages/reservation/index')">
					<text class="iconfont icon-reservation animated-icon" style="font-size: 50rpx; color: #9ccc65;"></text>
					<text class="block mt-10">预约</text>
				</view>
				<view class="grid-item p-20" @click="goToPage('/pages/play/index')">
					<text class="iconfont icon-play animated-icon" style="font-size: 50rpx; color: #7cb342;"></text>
					<text class="block mt-10">吃喝玩乐</text>
				</view>
			</view>
		</view>
		
		<!-- 朋友圈动态 -->
		<view class="card mb-20">
			<view class="flex justify-between mb-20">
				<text class="title">朋友圈动态</text>
				<text class="text-primary">更多 ></text>
			</view>
			<view class="moments-list">
				<view class="moment-item mb-20" v-for="(item, index) in momentsList" :key="index">
					<view class="flex align-center mb-10">
						<image :src="item.avatar" mode="aspectFill" style="width: 60rpx; height: 60rpx; border-radius: 50%;"></image>
						<view class="ml-10">
							<text class="block">{{ item.username }}</text>
							<text class="text-gray" style="font-size: 24rpx;">{{ item.time }}</text>
						</view>
					</view>
					<text class="block mb-10">{{ item.content }}</text>
					<view class="moment-images" v-if="item.images.length > 0">
						<image 
							v-for="(img, imgIndex) in item.images" 
							:key="imgIndex" 
							:src="img" 
							mode="aspectFill" 
							style="width: 220rpx; height: 220rpx; border-radius: 10rpx; margin: 5rpx;"
							@tap="previewImage(item.images, imgIndex)">
						</image>
					</view>
					<!-- 没有图片时的占位 -->
					<view class="moment-images-placeholder" v-else>
						<view class="placeholder-image"></view>
					</view>
					<view class="flex justify-between mt-10">
						<text class="text-gray">{{ item.location }}</text>
						<view class="flex align-center">
							<text class="iconfont icon-like text-gray mr-10"></text>
							<text class="text-gray">{{ item.likes }}</text>
						</view>
					</view>
				</view>
			</view>
		</view>
		
		<!-- 热门推荐 -->
		<view class="card mb-20">
			<view class="flex justify-between mb-20">
				<text class="title">热门推荐</text>
				<text class="text-primary">更多 ></text>
			</view>
			<view class="recommend-list">
				<view class="recommend-item flex mb-20" v-for="(item, index) in recommendList" :key="index" @click="goToDetail(item)">
					<image :src="item.image" mode="aspectFill" style="width: 200rpx; height: 150rpx; border-radius: 10rpx;"></image>
					<view style="flex: 1; margin-left: 20rpx;">
						<text class="block" style="font-weight: bold;">{{ item.title }}</text>
						<text class="block text-gray mt-10">{{ item.desc }}</text>
						<view class="flex justify-between mt-10">
							<text class="text-red">¥{{ item.price }}</text>
							<text class="text-gray">{{ item.sales }}人已购买</text>
						</view>
					</view>
				</view>
			</view>
		</view>
		
		<!-- 旅游攻略 -->
		<view class="card mb-20">
			<view class="flex justify-between mb-20">
				<text class="title">热门攻略</text>
				<text class="text-primary">更多 ></text>
			</view>
			<view class="strategy-list">
				<view class="strategy-item mb-20" v-for="(item, index) in strategyList" :key="index" @click="goToStrategyDetail(item)">
					<image :src="item.image" mode="widthFix" style="width: 100%; border-radius: 10rpx; height: 200rpx;"></image>
					<view class="mt-10">
						<text class="block" style="font-weight: bold;">{{ item.title }}</text>
						<view class="flex justify-between mt-10">
							<view class="flex align-center">
								<image :src="item.authorAvatar" mode="aspectFill" style="width: 40rpx; height: 40rpx; border-radius: 50%; margin-right: 10rpx;"></image>
								<text class="text-gray">{{ item.author }}</text>
							</view>
							<view class="flex">
								<text class="iconfont icon-eye text-gray mr-5"></text>
								<text class="text-gray mr-10">{{ item.views }}</text>
								<text class="iconfont icon-like text-gray mr-5"></text>
								<text class="text-gray">{{ item.likes }}</text>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		
		<!-- 使用自定义tabbar组件 -->
		<custom-tabbar :current-index="0"></custom-tabbar>
	</view>
</template>

<script>
// 引入自定义tabbar组件
	import CustomTabbar from '@/components/custom-tabbar/custom-tabbar.vue';
	
	export default {
		components: {
			CustomTabbar
		},
		data() {
			return {
				currentIndex: 0,
				recommendList: [
					{
						id: 1,
						title: '故宫博物院',
						desc: '明清两代的皇家宫殿，世界上现存规模最大、保存最完整的木质结构古建筑之一',
						price: 60,
						sales: 1280,
						image: '/static/gugong.jpg'
					},
					{
						id: 2,
						title: '北京环球影城',
						desc: '全球首个"功夫熊猫盖世之地"主题景区，沉浸式体验中国武侠文化',
						price: 528,
						sales: 3200,
						image: '/static/huanqiu.jpg'
					}
				],
				momentsList: [
					{
						id: 1,
						username: '旅行达人小王',
						avatar: '/static/avatar.jpg',
						time: '2小时前',
						content: '今天终于打卡了心心念念的故宫！红墙黄瓦真的太美了，每一处都值得细细品味。推荐大家一定要提前预约门票哦～',
						images: ['/static/gugong.jpg', '/static/yiheyuan.jpg', '/static/changcheng.jpg'],
						location: '北京·故宫博物院',
						likes: 24
					},
					{
						id: 2,
						username: '美食探索家',
						avatar: '/static/avatar.jpg',
						time: '5小时前',
						content: '这家胡同里的老北京炸酱面真的太正宗了！地道的老北京味道，分量足价格还便宜。来北京的朋友一定要试试～',
						images: [], // 没有图片的情况
						location: '北京·前门大街',
						likes: 18
					}
				],
				strategyList: [
					{
						id: 1,
						title: '北京三日游全攻略，带你玩转帝都',
						image: '/static/banner1.jpg',
						author: '旅游攻略君',
						authorAvatar: '/static/avatar.jpg',
						views: 1280,
						likes: 96
					},
					{
						id: 2,
						title: '北京夏日避暑好去处推荐',
						image: '/static/banner2.jpg',
						author: '清凉一夏',
						authorAvatar: '/static/avatar.jpg',
						views: 860,
						likes: 72
					}
				],
				tabBarList: [
					{ icon: 'icon-home', text: '首页' },
					{ icon: 'icon-order', text: '订单' },
					{ icon: 'icon-user', text: '我的' }
				]
			}
		},
		methods: {
			goToPage(url) {
				uni.navigateTo({
					url: url
				})
			},
			goToDetail(item) {
				uni.navigateTo({
					url: '/pages/detail/index?id=' + item.id
				})
			},
			goToStrategyDetail(item) {
				uni.navigateTo({
					url: '/pages/info/detail?id=' + item.id
				})
			},
			previewImage(images, index) {
				uni.previewImage({
					current: index,
					urls: images
				})
			}
		}
	}
</script>

<style>
	.grid {
		display: flex;
		flex-wrap: wrap;
	}
	
	.grid-col-5 .grid-item {
		width: 20%;
		box-sizing: border-box;
	}
	
	.recommend-item {
		border-bottom: 1rpx solid #eee;
		padding-bottom: 20rpx;
	}
	
	.recommend-item:last-child {
		border-bottom: none;
	}
	
	/* 自定义tabbar样式 */
	/* .custom-tabbar {
		background: linear-gradient(90deg, #007AFF, #5856d6);
		border-top: none;
	} */
	
	/* .tab-bar .tab-item {
		position: relative;
		color: rgba(255, 255, 255, 0.7);
	} */
	
	/* .tab-bar .tab-item.active {
		color: #fff;
		font-weight: bold;
	} */
	
	/* 水波动画 */
	/* .ripple {
		position: absolute;
		top: 50%;
		left: 50%;
		width: 80rpx;
		height: 80rpx;
		border-radius: 50%;
		transform: translate(-50%, -50%);
		animation: ripple 1.5s infinite;
	} */
	
	/* @keyframes ripple {
		0% {
			box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.3);
		}
		100% {
			box-shadow: 0 0 0 20rpx rgba(255, 255, 255, 0);
		}
	} */
	
	/* 图标动画 */
	.animated-icon {
		animation: jump 2s infinite;
	}
	
	@keyframes jump {
		0%, 100% {
			transform: translateY(0);
		}
		50% {
			transform: translateY(-10rpx);
		}
	}
	
	/* 朋友圈动态样式 */
	.moment-images {
		display: flex;
		flex-wrap: wrap;
	}
	
	/* 搜索栏样式优化 */
	.search-bar {
		background: linear-gradient(90deg, #4caf50, #8bc34a); /* 青春绿色渐变 */
		border-radius: 30rpx;
		padding: 15rpx;
		color: #fff;
		box-shadow: 0 4rpx 12rpx rgba(76, 175, 80, 0.3); /* 绿色阴影 */
	}
	
	.search-input-container {
		flex: 1;
		background: rgba(255, 255, 255, 0.2);
		border-radius: 30rpx;
		padding: 0 20rpx;
		margin-right: 20rpx;
	}
	
	.search-icon {
		color: #fff;
		margin-right: 10rpx;
	}
	
	.search-input {
		flex: 1;
		background: transparent;
		color: #fff;
		height: 60rpx;
	}
	
	.search-input::placeholder {
		color: #fff;
	}
	
	.search-button {
		font-weight: bold;
		padding: 0 20rpx;
		color: #fff;
	}
	
	/* 没有图片时的占位样式 */
	.moment-images-placeholder {
		display: flex;
		justify-content: center;
		align-items: center;
		width: 100%;
		height: 220rpx;
		background: linear-gradient(135deg, #e0f7e0, #c8e6c9); /* 青春绿色渐变背景 */
		border-radius: 10rpx;
		border: 2rpx dashed #a5d6a7; /* 虚线边框 */
	}
	
	.placeholder-image {
		width: 80rpx;
		height: 80rpx;
		background: linear-gradient(135deg, #4caf50, #8bc34a); /* 青春绿色渐变 */
		border-radius: 50%;
		position: relative;
		box-shadow: 0 4rpx 10rpx rgba(76, 175, 80, 0.3); /* 绿色阴影 */
	}
	
	/* 在.placeholder-image中添加加号图标 */
	.placeholder-image::after {
		content: "+";
		position: absolute;
		top: 50%;
		left: 50%;
		transform: translate(-50%, -50%);
		color: white;
		font-size: 40rpx;
		font-weight: bold;
	}
</style>